package com.jdrx.sw.sewage.beans.vo;

import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel(value = "点位", description = "点位")
@Data
public class GatherDevPointOptionVO {
	private Long id;
	
    @ApiModelProperty(value = "点位名称")
    private String name;

    @ApiModelProperty(value = "点位编码(遵循命名规范YYC1_JBJ1_GZ)")
    private String code;
    
    @ApiModelProperty(value = "点位值，对应parValue")
    private String value;
    
    @ApiModelProperty(value = "点位单位")
    private String parUnit;

    // 截取value中设备编号用以组装name
	public String getName() {
		Pattern pattern = Pattern.compile("\\d+$");
		// 分割点位命名
		String[] values = StringUtils.split(code, "_");
		// 取点位命名中设备部分中的数字序号
		Matcher matcher = pattern.matcher(values[1]);
		if(matcher.find()) {
			name = matcher.group() + "#" + name;
		}
		return name;
	}
	
	// 处理数值精度问题
	public String getValue() {
		if(NumberUtils.isCreatable(value)) {
			value = new BigDecimal(value).setScale(2, BigDecimal.ROUND_DOWN).toString();
		}
		return value;
	}
}